
(* ------------------------------------------------------------------------------------------- *)
signature UserDefined_Sig =
sig
		
		(* The structure is: (function_id_string, function implementation in SML) list *)
		val functions : (
							string 
							* 
							(
								(ABSTRACT_REPRESENTATION.EXPR list * ABSTRACT_REPRESENTATION.EXPR list) list 
								-> 
								ABSTRACT_REPRESENTATION.EXPR
							)
                        ) list;
end;
(* ------------------------------------------------------------------------------------------- *)



(* =========================================================================================== *)
(* -------------------------------UserDefined------------------------------------------------- *)
(* =========================================================================================== *)
structure UserDefined : UserDefined_Sig = struct
open ABSTRACT_REPRESENTATION;


(* ------------------------------------------------------------------------------------------- *)  		
fun pp [ program ] =
		(
			Input_Output.pp(program, "pp");
			TRUE 
		)
  | pp _ = raise General.Fail("Error in UserDefined.pp: inappropriate arguments to function.\n");
  
(* ------------------------------------------------------------------------------------------- *)  
fun outputTransformed [ program ] =
		let
			val transformed_program = Strategic_Values.getTerm program
			val output_filename     = Environment.getTransformed_filename()
		in	
			Input_Output.outputXML(transformed_program,output_filename);
			TRUE 
		end
  | outputTransformed _ = raise General.Fail("Error in UserDefined.outputTransformed: inappropriate arguments to function.\n");

(* ------------------------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------------------------- *) 

(* ------------------------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------------------------- *)
(*                                 Exported Function List                                      *)
(* ------------------------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------------------------- *)
(* stub element:     ("showEnvironment", (fn [ ( [TRUE], [TRUE]) ] => TRUE)) *)

	fun member( id1, (id2, _) :: rest) = (id1 = id2) orelse member(id1, rest)
	  | member( _, [] )                = false;
	 
	fun checkUnique( (x_str, x_fun) :: rest ) = if member(x_str, rest) then raise General.Fail("Error in UserDefined: The set of TL exported functions contains the duplicate name: " ^ x_str ^ "\n") 
												else checkUnique(rest)
      | checkUnique( [] ) = true												



    val functions = 

	Strategic_Views.functions
	@
	Clocks.functions
	@
	Ids.functions
	@
	Environment.functions
	@
	
	[
		("pp"							, pp							),
		("outputTransformed"			, outputTransformed				)		
	];


	val _ = checkUnique functions;
	


(* ------------------------------------------------------------------------------------------- *)

end; (* struct *)

(* ------------------------------------------------------------------------------------------- *)

